package com.amoyt.project.service.admin.impl;

import com.amoyt.project.domain.dto.query.LogPageQuery;
import com.amoyt.project.domain.pojo.OperationLog;
import com.amoyt.project.domain.res.PageResult;
import com.amoyt.project.domain.res.Result;
import com.amoyt.project.mapper.OperationLogMapper;
import com.amoyt.project.service.admin.OperationLogService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Date: 2025/8/24
 * @Time: 10:06
 * @Author: TQ_QT
 * @Description:
 */
@Service
public class OperationLogServiceImpl implements OperationLogService {
    @Autowired
    private OperationLogMapper operationLogMapper;

    @Override
    public Result list(LogPageQuery query) {
        //查询
        Page<OperationLog> page = new Page<>(query.getPage(), query.getPageSize());
        Page<OperationLog> operationLogPage = operationLogMapper.queryLogList(page, query);

        //封装结构
        PageResult pageResult = PageResult.builder()
                .total(operationLogPage.getTotal())
                .records(operationLogPage.getRecords())
                .build();

        return Result.success(pageResult);
    }

    @Override
    public Result delete(List<Long> logIds) {
        operationLogMapper.deleteBatchIds(logIds);
        return Result.success();
    }
}
